﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExRev.Engine.Utils
{
    public class TextLogger : Logger
    {
        internal TextLogger(string name, string path) 
            : base(name, path) 
        {
            Extention = ".txt";
        }

        public override bool Log(LogLevel level, string message)
        {
            if (string.IsNullOrEmpty(message)) {
                return false;
            }

            StringBuilder sb = new StringBuilder();
            DateTime dateTime = DateTime.Now;

            sb.Append("[");
            sb.Append(dateTime.Hour).Append(":");
            sb.Append(dateTime.Minute).Append(":");
            sb.Append(dateTime.Second).Append(".");
            sb.Append(dateTime.Millisecond).Append("] ");

            // Logline:
            // [hh:mm:ss.ms] LoggerLevel - Message
            switch (level) {
                case LogLevel.Debug:
                    sb.Append("Debug - ");
                    break;
                case LogLevel.Info:
                    sb.Append("Info - ");
                    break;
                case LogLevel.Warn:
                    sb.Append("Warning - ");
                    break;
                case LogLevel.Error:
                    sb.Append("Error - ");
                    break;
                case LogLevel.Fatal:
                    sb.Append("Fatal Error - ");
                    break;
                case LogLevel.Verbose:
                    sb.Append("Verbose - ");
                    break;
                default:
                    return false;
            }
            sb.Append(message);
            message = sb.ToString();

            return base.Write(message);
        }
    }
}
